<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item to="/dashboard">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="user-manage">
      <el-form :model="info" label-width="auto" :rules="rules">
        <el-form-item
          label="用户名"
          prop="username"
          :rules="[
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ]"
        >
          <el-input
            v-model="info.username"
            placeholder="请输入用户名"
            clearable
            maxlength="10"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="邮箱"
          prop="email"
          :rules="[
            { required: true, message: '请输入邮箱地址', trigger: 'blur' },
            {
              type: 'email',
              message: '请输入正确的邮箱地址',
              trigger: ['blur', 'change'],
            },
          ]"
        >
          <el-input v-model="info.email"></el-input>
        </el-form-item>

        <el-form-item label="博主类型" prop="blogger">
          <el-input v-model="info.blogger"></el-input>
        </el-form-item>

        <el-form-item label="旧密码" prop="password">
          <el-input
            type="password"
            v-model="info.password"
            auto-complete="off"
          ></el-input>
        </el-form-item>

        <el-form-item label="新密码" prop="newpwd">
          <el-input
            type="password"
            v-model="info.newpwd"
            auto-complete="off"
          ></el-input>
        </el-form-item>

        <el-form-item label="确认密码" prop="newpwd1">
          <el-input
            type="password"
            v-model="info.newpwd1"
            autp-complete="off"
          ></el-input>
        </el-form-item>

        <el-form-item class="btn">
          <el-button type="primary">提交</el-button>
          <el-button @click="clearvalue">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Manage',
  data() {
    var validatePass = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入新密码'))
      } else if (value.toString().length < 6 || value.toString().length > 18) {
        callback(new Error('密码长度为6-18位'))
      } else {
        callback()
      }
    }

    var validatePass1 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.info.newpwd) {
        callback(new Error('两次输入密码不一致'))
      } else {
        callback()
      }
    }
    return {
      info: {
        username: '',
        email: '',
        blogger: '',
        password: '',
        newpwd: '',
        newpwd1: '',
      },
      rules: {
        password: [
          { required: true, message: '请输入旧密码', trigger: 'blur' },
        ],
        newpwd: [{ required: true, validator: validatePass, trigger: 'blur' }],
        newpwd1: [
          { required: true, validator: validatePass1, trigger: 'blur' },
        ],
      },
    }
  },
}
</script>

<style>
.user-manage {
  margin-top: 20px;
  min-width: 300px;
  text-align: center;
}
.el-form {
  width: 50%;
  margin: 50px 0 30px 0;
}
.btn {
  margin: 20px 0 0;
}
</style>
-->

<!-- <template>
  <div class="app-container common-list-page">
    <el-form
      :model="resetForm"
      :rules="resetFormRules"
      ref="resetForm"
      status-icon
      label-width="100px"
    >
      
      <el-form-item>
        <el-button type="primary" @click.native.prevent="toAmend"
          >确认修改</el-button
        >
      </el-form-item>
      
    </el-form>
  </div>
</template>

<script>
export default {
  
  methods: {
    toAmend() {
      this.$refs.resetForm.validate((valid) => {
        if (valid) {
          //这里的api.materialQuery.toAmend是调用前期我们统一的api接口url路径，不作参考 ，只要把后台需要的字段正常传进去即可
          api.materialQuery
            .toAmend(this.resetForm)
            .then((res) => {
              if (res.code === 2) {
                this.$message({
                  message: res.msg,
                  type: 'error',
                  duration: '2000',
                })
                return false
              }
              if (res.code === 0) {
                this.$message.success('修改成功,3秒后跳转到登录页！')
                setTimeout(() => {
                  this.logout() //调用跳转到登陆页的方法
                }, 3000)
              }
              ic
            })
            .catch(() => {})
        }
      })
    },
    //这是修改成功后重新返回登陆页的方法，看个人需要自行调整
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login`)
    },
  },
}
</script>

<style></style> -->
